/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
 * \file
 * \brief Protocol encoder/decoder for the Alarm protocol.
 * \author Antti Maula <antti.maula@tkk.fi>
 */
#ifndef _MACI_ALARMDATA_HPP_
#define _MACI_ALARMDATA_HPP_
#include "AlarmTypes.hpp"
#include "MaCIData.hpp"
#include "common/timestamp.hpp"
#include <vector>
#include <map>

namespace MaCI {
  namespace Alarm {

    /** Return a string describing the alarm type.
     *
     * This function returns a textual representation for a alarm
     * type.  For unknown alarm types, string 'Unknown' is returned.
     *
     * @return                  Alarm type string, or 'Unknown' if 
     *                          type is unknown.
     */
    std::string GetAlarmEventTypeStr(const EAlarmEventType &ae);


    /** Alarm protocol parser.
     *
     * This class contains the methods for decoding/encoding a 
     * Alarm message.
     */
    class CAlarmData : public CMaCIData
    {
    public:
      CAlarmData();
      ~CAlarmData();

      CAlarmData(const CAlarmData &);
      CAlarmData &operator=(const CAlarmData &);

      // Interface for moving data around
      bool DecodeFrom(gim::binbag::CBinBag *aBinBag);
      void Reset();
      void Print(const int level) const;


      /** Set timestamp element.
       * 
       */
      bool SetTimestamp(const Common::TTimestamp &aStamp);


      /** Set command element.
       * This function stores a element of type TCommand.
       *
       * @return                'true' if element was succesfully added,
       *                        'false' if element already exists.
       */
      bool SetCommand(const TCommand &aCmd);

      
      /** Set AlarmEvent element.
       *
       * This function stores a element of type TAlarmEvent.
       *
       *
       * @return                'true' if element was succesfully added,
       *                        'false' if element already exists.
       */
      bool SetAlarmEvent(const TAlarmEvent &aEvent);


      /** Set Text element.
       *
       * This function stores a element of type TText. The function
       * differs from other in the interface so, that it doesn't add
       * the raw 'TText' element as itself, but rather takes the real
       * 'Text' and forms&adds the correct TText element based on
       * that. The different behaviour is required because of the
       * nature of variable size text field size.
       *
       * \note This function can be only called right after calling
       * 'SetAlarmEvent' or 'SetHeadingText' function. TText element
       * can not be added alone.
       *
       * @return                'true' if element was succesfully added,
       *                        'false' if element already exists, or the 
       *                        previously inserted element was not 
       *                        TAlarmEvent.
       */
      bool SetText(const std::string &aText);

      
      /** Set HeadingText element.
       *
       * This function stores a element of type THeadingText. The
       * function differs from other in the interface so, that it
       * doesn't add the raw 'THeadingText' element as itself, but
       * rather takes the real 'Text' and forms&adds the correct
       * THeadingText element based on that. The different behaviour
       * is required because of the nature of variable size text field
       * size.
       *
       * \note This function can be only called right after calling
       * 'SetAlarmEvent' function. TText element can not be added
       * alone.
       *
       * @return                'true' if element was succesfully added,
       *                        'false' if element already exists, or the 
       *                        previously inserted element was not 
       *                        TAlarmEvent.
       */
      bool SetHeadingText(const std::string &aHeading);


      /** Set SourceNameText element.
       *
       * This function stores a element of type TSourceNameText. The
       * function differs from other in the interface so, that it
       * doesn't add the raw 'TSourceNameText' element as itself, but
       * rather takes the real 'Text' and forms&adds the correct
       * TSourceNameText element based on that. The different
       * behaviour is required because of the nature of variable size
       * text field size.
       *
       * @return                'true' if element was succesfully added,
       *                        'false' if element already exists
       */
      bool SetSourceNameText(const std::string &aSourceName);


      /** Get pointer to TTimestamp element.
       * 
       * @return                 Pointer to element if such exists, 
       *                         NULL if element doesn't exists in the
       *                         container.
       */
      const MaCI::Common::TTimestamp *GetTimestamp(void) const;
      

      /** Get pointer to TCommand element.
       *
       * @return                 Pointer to element if such exists, 
       *                         NULL if element doesn't exists in the
       *                         container.
       */
      const TCommand *GetCommand(void) const;


      /** Get pointer to TAlarmEvent element.
       *
       * @return                 Pointer to element if such exists, 
       *                         NULL if element doesn't exists in the
       *                         container.
       */
      const TAlarmEvent *GetAlarmEvent(void) const;


      /** Get pointer to TText element.
       *
       * @return                 Pointer to element if such exists, 
       *                         NULL if element doesn't exists in the
       *                         container.
       */
      const TText *GetText(void) const;


      /** Get pointer to THeadingText element.
       *
       * @return                 Pointer to element if such exists, 
       *                         NULL if element doesn't exists in the
       *                         container.
       */
      const THeadingText *GetHeadingText(void) const;


      /** Get pointer to TSourceNameText element.
       *
       * @return                 Pointer to element if such exists, 
       *                         NULL if element doesn't exists in the
       *                         container.
       */
      const TSourceNameText *GetSourceNameText(void) const;
      
      
    private:
      const Common::TTimestamp *iTimestampPtr; ///< Pointer to timestamp if exists
      const TCommand *iCommandPtr; ///< Pointer to command if any.
      const TAlarmEvent *iAlarmEventPtr; ///< Pointer to Alarm event.
      const TText *iTextPtr; ///< Pointer to Text element BEGIN.
      const THeadingText *iHeadingTextPtr; ///< Pointer to Text element BEGIN.
      const TSourceNameText *iSourceNameTextPtr; ///< Pointer to Text element BEGIN.
    };
    
  }
}

#endif
